#!/usr/bin/python
# Checkout program for adxl345 accelerometer and ITG-3200 gyro

I2C_BUS_NUMBER = 3
ADXL_ADDR = 0x53
ITG_ADDR = 0x68

from smbus import SMBus

b = SMBus(I2C_BUS_NUMBER)

#initalization

# sets accel to normal power and 12.5Hz sample rate
b.write_byte_data(ADXL_ADDR,0x2C,0x07) 
# sets accel to measure mode
b.write_byte_data(ADXL_ADDR,0x2D,0x08)

# set gyro to 2000deg/sec
b.write_byte_data(ITG_ADDR,0x16,0x18)

while True:
	X_raw = (b.read_byte_data(ADXL_ADDR,0x33) << 8 ) + b.read_byte_data(ADXL_ADDR,0x32)
	Y_raw = (b.read_byte_data(ADXL_ADDR,0x35) << 8 ) + b.read_byte_data(ADXL_ADDR,0x34)
	Z_raw = (b.read_byte_data(ADXL_ADDR,0x37) << 8 ) + b.read_byte_data(ADXL_ADDR,0x36)
	print repr(X_raw).rjust(2), repr(Y_raw).rjust(2), repr(Z_raw).rjust(2)
	Xrot_raw = (b.read_byte_data(ITG_ADDR,0x1D) << 8 ) + b.read_byte_data(ITG_ADDR,0x1E)
	Yrot_raw = (b.read_byte_data(ITG_ADDR,0x1F) << 8 ) + b.read_byte_data(ITG_ADDR,0x20)
	Zrot_raw = (b.read_byte_data(ITG_ADDR,0x21) << 8 ) + b.read_byte_data(ITG_ADDR,0x22)
	print repr(Xrot_raw).rjust(2), repr(Yrot_raw).rjust(2), repr(Zrot_raw).rjust(2)
